home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / MacTCP / MacTCP Developer Tools / HyperCard MacTCP Toolkit 1.0 / Source Code ƒ / TCPState.p < prev    next >
Encoding:
Text File  |  1994-11-21  |  1.8 KB  |  79 lines  |  [TEXT/MPS ]

  1. (*
  2.     TCPState(connectionID) -- Return the state of the TCP connection.
  3.  
  4.     To compile and link this file using Macintosh Programmer's Workshop,
  5.  
  6.         pascal -w TCPState.p
  7.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=7867 -sn Main=TCPState ∂
  8.             TCPState.p.o "{Libraries}HyperXLib.o" "{MPW}"Libraries:interface.o
  9.  
  10.     © Copyright 1988 by Apple Computer, Inc.
  11.  
  12.     Initial coding 12/88 by Harry R. Chesley.
  13. *)
  14.  
  15. {$R-}
  16.  
  17. {$S TCPState }     { Segment name must be the same as the command name. }
  18.  
  19. unit DummyUnit;
  20.  
  21. interface
  22.  
  23. uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
  24.  
  25. procedure EntryPoint(paramPtr: XCmdPtr);
  26.     
  27. implementation
  28.  
  29. procedure TCPState(paramPtr: XCmdPtr); forward;
  30.  
  31. procedure EntryPoint(paramPtr: XCmdPtr);
  32.  
  33.     begin
  34.         TCPState(paramPtr);
  35.     end;
  36.  
  37. procedure TCPState(paramPtr: XCmdPtr);
  38.  
  39.     var state: Str255;
  40.  
  41.     procedure Fail(errMsg: Str255); { set theResult and quit }
  42.         begin
  43.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  44.             exit(TCPState);
  45.         end;
  46.  
  47.     {$I TCPUtil.inc}
  48.  
  49.     begin
  50.         if paramPtr^.paramCount <> 1 then Fail('§§§ parameter count is not 1 §§§');
  51.  
  52.         SetUpConnectionID;
  53.  
  54.         { Check for an open still in progress (note that this control block, particularly the ioResult
  55.             field was copied from the async control block by SetUpConnectionID. }
  56.         if SyncControlBlock.ioResult > 0 then state := 'waiting for open'
  57.         else
  58.             begin
  59.                 { Read status. }
  60.                 ZeroIOParms;
  61.                 SyncControlBlock.csCode := TCPcsStatus;
  62.                 if PBControl(@SyncControlBlock,false) <> noErr then state := 'closed'
  63.                 else
  64.                     { Decode status into text. }
  65.                     case ControlByteAtOffset(52) of
  66.                         0: state := 'closed';
  67.                         2: state := 'listening';
  68.                         4,6: state := 'opening';
  69.                         8: state := 'established';
  70.                         10,12,16,18,20: state := 'closing';
  71.                         14: state := 'please close';
  72.                         otherwise state := 'unknown state';
  73.                         end;
  74.             end;
  75.         paramPtr^.returnValue := PasToZero(paramPtr,state);
  76.     end;
  77.  
  78. end.
  79.